

[CCode(cheader_filename="mongoc/mongoc.h", cprefix = "mongoc_")]
namespace Mongoc {

    //  [CCode(cname = "mongoc_init")]
    public void init();
    //  [CCode(cname = "mongoc_cleanup")]
    public void cleanup();
    [CCode(cname = "log_level_t", cprefix = "MONGOC_LOG_LEVEL_", has_type_id = false)]
    public enum MongocLogLevel {
        ERROR,
        CRITICAL,
        WARNING,
        MESSAGE,
        INFO,
        DEBUG,
        TRACE
    }
    [Compact]
    [CCode(free_function = "mongoc_uri_destroy", cname = "mongoc_uri_t")]
    public class Uri {
        [CCode(cname = "mongoc_uri_new")]
        public Uri(string uri);
        public Uri copy();
        [CCode(cname = "mongoc_uri_new_for_host_port")]
        public Uri.for_host_port(string host, uint16 port);
        [CCode(cname = "mongoc_uri_new_with_error")]
        public Uri.with_error(string uri_string, out Bson.BsonError error);
        public static string unescape(string escaped_string);
        public static bool has_option(string option);
        [CCode(cname ="mongoc_uri_option_is_bool")]
        public static bool option_is_bool(string option);
        [CCode(cname ="mongoc_uri_option_is_int32")]
        public static bool option_is_int32(string option);
        [CCode(cname ="mongoc_uri_option_is_int64")]
        public static bool option_is_int64(string option);
        [CCode(cname ="mongoc_uri_option_is_utf8")]
        public static bool option_is_utf8(string option);
        public bool set_option_as_bool(string option, bool value);
        public bool set_option_as_int32(string option, uint32 value);
        public bool set_option_as_int64(string option, uint64 value);
        public bool set_option_as_utf8(string option, string value);
        public bool get_option_as_bool(string option, bool fallback);
        public int32 get_option_as_int32(string option, uint32 fallback);
        public int64 get_option_as_int64(string option, uint64 fallback);
        public unowned string get_option_as_utf8(string option, string fallback);
        public unowned string auth_mechanism { get;}
        public bool set_auth_mechanism(string value);
        public unowned string get_auth_mechanism();
        public string auth_source { get;}
        public bool set_auth_source(string value);
        public Bson.Bson compressors {get;}
        public unowned string database {get; set;}
        public bool get_mechanism_properties(out Bson.Bson bson);
        public unowned Bson.Bson options {get;}
        public unowned string username {get; set;}
        public unowned string password {get;set;}
        public unowned string get_string();
    }

    [Compact]
    [CCode(cname = "mongoc_client_t", free_function = "mongoc_client_destroy")]
    public class Client {
        [CCode(cname = "mongoc_client_new")]
        public Client(string uri);
        [CCode(cname = "mongoc_client_new_from_uri")]
        public Client.from_uri(Uri uri);
        public char **get_database_names_with_opts(Bson.Bson? options = null, out Bson.BsonError error = null);
        public string[] get_safe_database_names_with_opts(Bson.Bson? options = null, out Bson.BsonError error = null){
            return _convert_bson_strings_standard_strings(this.get_database_names_with_opts(options, out error));
        }
        public Database get_database(string name);
    }

    private string[] _convert_bson_strings_standard_strings(char **texts) {
        var list = new Gee.ArrayList<string>();
        for (var a = 0; (uint64)texts[a] != 0; a++) {
            var name = (string) texts[a];
            list.add(name);
        }
        Bson.free_strings(texts);
        return list.to_array();
    }

    [Compact]
    [CCode(cname = "mongoc_database_t", free_function = "mongoc_database_destroy")]
    public class Database {
        public bool add_user(string username, string password, Bson.Bson roles, Bson.Bson? custom_data = null, out Bson.BsonError error = null);
        //  [CCode(cname = "mongoc_database_get_collection_names_with_opts")]
        public char **get_collection_names_with_opts(Bson.Bson? options = null, out Bson.BsonError error = null);
        public string[] get_safe_collection_names_with_opts(Bson.Bson? options = null, out Bson.BsonError error = null) {
            return _convert_bson_strings_standard_strings(this.get_collection_names_with_opts(options, out error));
        }
        public Collection create_collection(string collection_name, Bson.Bson options = null, out Bson.BsonError error = null);
        public Collection get_collection(string collection_name);
        public bool has_collection(string collection_name, out Bson.BsonError error = null);
        public Collection copy();
        public Collection drop(out Bson.BsonError error = null);
        public bool remove_user(string username, out Bson.BsonError error = null);
        public bool remove_all_users(out Bson.BsonError error = null);
        public string name {get;}
    }
    [Compact]
    [CCode(cname = "mongoc_collection_t", free_function = "mongoc_collection_destroy")]
    public class Collection {
        public Collection copy();
        public bool rename(string new_database_name, string new_collection_name, bool drop_target_before_rename, out Bson.BsonError error = null);
        public bool insert_one(Bson.Bson document, Bson.Bson options = null, Bson.Bson replay = null, out Bson.BsonError error = null);
        public bool insert_many(Bson.Bson[] document, Bson.Bson options = null, out Bson.Bson replay = null, out Bson.BsonError error = null);
        //  public Cursor find_with_ops(Bson.Bson filter, Bson.Bson options = null);
    }
}


